window.onload = function () {
    function paste_img(e) {
        if (e.clipboardData.items) {
            var ele = e.clipboardData.items
            for (var i = 0; i < ele.length; ++i) {
                if (ele[i].kind == 'file' && ele[i].type.indexOf('image/') !== -1) {
                    var blob = ele[i].getAsFile();
                    window.URL = window.URL || window.webkitURL;
                    var blobUrl = window.URL.createObjectURL(blob);
                    convertImgToBase64(blobUrl, function(base64Img){
                        var a =document.querySelector("#editable")
                        a.value = base64Img
                        a.select()
                        document.execCommand("copy")
                        alert("复制成功")
                    });
                }
            }
        } else {
            alert('您的浏览器不支持粘贴图片功能,请换更高版本浏览器.');
        }
    }
    document.getElementById('editable').onpaste = function () {
        paste_img(event);
        return false;
    };
}
function convertImgToBase64(url, callback, outputFormat){
    var canvas = document.createElement('CANVAS'),
        ctx = canvas.getContext('2d'),
        img = new Image;
    img.crossOrigin = 'Anonymous';
    img.onload = function(){
        canvas.height = img.height;
        canvas.width = img.width;
        ctx.drawImage(img,0,0);
        var dataURL = canvas.toDataURL(outputFormat || 'image/png');
        callback.call(this, dataURL);
        canvas = null;
    };
    img.src = url;
}

